﻿package com.valeosys.utils{
	import flash.display.*;
	public class QuickRect{
	
		public static function rect(bg:uint,w:Number,h:Number):Sprite{
			var r:Sprite = new Sprite();
			r.graphics.beginFill(bg);
			r.graphics.drawRect(0,0,w,h);
			r.graphics.endFill();
			return r;
			
		}
		public static function rectM(bg:uint,w:Number,h:Number):MovieClip{
			var r:MovieClip = new MovieClip();
			r.graphics.beginFill(bg);
			r.graphics.drawRect(0,0,w,h);
			r.graphics.endFill();
			return r;
			
		}
		public static function tri(bg:int,len:Number):Sprite{
			
			var p= Math.sqrt((Math.pow(len,2))-Math.pow(len/2,2));
			var t:Sprite = new Sprite();
			t.graphics.beginFill(bg);
			//t.graphics.lineTo(0,0);
			t.graphics.lineTo(len,0);
			t.graphics.lineTo(len/2,p);
			t.graphics.lineTo(0,0);
			t.graphics.endFill();
			return t;
			
		}
		public static function circ(color:uint,radius:Number){
			var c:Sprite = new Sprite();
			c.graphics.beginFill(color);
			c.graphics.drawCircle(0,0,radius);
			c.graphics.endFill();
			return c;
		}
		public static function dottedLine(color:uint, len:Number, lh:Number, space:Number){
			
			var bitdata:BitmapData = new BitmapData(len,2*lh);
			var cont:Sprite = new Sprite();
			var cir:Sprite;
			
			for(var i=lh; i<len; i+=space){
				cir = QuickRect.circ(color,lh);
				cont.addChild(cir);
				cir.y= lh;
				cir.x=i;
			}
			bitdata.draw(cont);
			var bitmap:Bitmap = new Bitmap(bitdata);
			return bitmap;
		}
		public static function countDuplicate(myarray:Array){
				var obj={}, i=myarray.length, arr=[], t, arr2=[];
				while(i--){
					t = myarray[i];
					if(obj[t]){
						obj[t][0] ++;
					}else{
						obj[t] = [1,t];
					}
				}
				for(i in obj){
					if(obj[i][0] > 1) arr.push(obj[i]);
				}
				return arr.length;
				
		}
		
		
	}

}